<?php

class Menu
{
    protected static $rules = [
        [
            'moduleid' => 2,
            'module_en' => 'member',
            'module_cn' => '会员管理',
            'module_dir' => 'member',
            'is_auth' => 1,
            'power' => [
                ['name' => 'add', 'chinese' => '添加会员', 'is_auth' => 1, 'note' => '', 'is_menu' => 1],
                ['name' => 'lst', 'chinese' => '会员列表', 'is_auth' => 1, 'note' => '', 'is_menu' => 1],
                ['name' => 'mod', 'chinese' => '编辑会员', 'is_auth' => 1, 'note' => '', 'is_menu' => 0],
                ['name' => 'del', 'chinese' => '删除会员', 'is_auth' => 1, 'note' => '', 'is_menu' => 0],
                ['name' => 'preview', 'chinese' => '预览会员', 'is_auth' => 1, 'note' => '', 'is_menu' => 0],
                ['name' => 'authenticate', 'chinese' => '后台权限', 'is_auth' => 1, 'note' => '', 'is_menu' => 0],
            ],
        ],
        [
            'moduleid' => 11,
            'module_en' => 'article',
            'module_cn' => '文章管理',
            'module_dir' => 'article',
            'is_auth' => 1,
            'power' => [
                ['name' => 'add', 'chinese' => '添加文章', 'is_auth' => 1, 'note' => '', 'is_menu' => 1],
                ['name' => 'lst', 'chinese' => '文章列表', 'is_auth' => 1, 'note' => '', 'is_menu' => 1],
                ['name' => 'mod', 'chinese' => '编辑文章', 'is_auth' => 1, 'note' => '', 'is_menu' => 0],
                ['name' => 'del', 'chinese' => '删除文章', 'is_auth' => 1, 'note' => '', 'is_menu' => 0],
                ['name' => 'preview', 'chinese' => '查看文章', 'is_auth' => 1, 'note' => '', 'is_menu' => 0],
                ['name' => 'bit_update', 'chinese' => '批量操作', 'is_auth' => 1, 'note' => '', 'is_menu' => 0],
                ['name' => 'test', 'chinese' => '测试', 'is_auth' => 0, 'note' => '', 'is_menu' => 1],
                ['name' => 'category_add', 'chinese' => '添加分类', 'is_auth' => 1, 'note' => '', 'is_menu' => 1],
                ['name' => 'category_mod', 'chinese' => '编辑分类', 'is_auth' => 1, 'note' => '', 'is_menu' => 0],
                ['name' => 'category_lst', 'chinese' => '分类列表', 'is_auth' => 1, 'note' => '', 'is_menu' => 1],
                ['name' => 'category_del', 'chinese' => '删除分类', 'is_auth' => 1, 'note' => '', 'is_menu' => 0],
                ['name' => 'category_preview', 'chinese' => '查看分类', 'is_auth' => 1, 'note' => '', 'is_menu' => 0],
            ],
        ],
        [
            'moduleid' => 12,
            'module_en' => 'haha',
            'module_cn' => 'haha管理',
            'module_dir' => 'haha',
            'is_auth' => 0,
            'power' => [
                ['name' => 'add', 'chinese' => '添加haha', 'is_auth' => 1, 'note' => '', 'is_menu' => 1],

            ],
        ],

    ];

    public static function init()
    {
        $new_rules = [];
        foreach (self::$rules as $k => $v) {
            $new_power = [];
            foreach ($v['power'] as $kk => $vv) {
                $new_power[$vv['name']] = $vv;
            }
            $v['power'] = $new_power;
            $new_rules[$v['moduleid']] = $v;
            $new_rules[$v['module_en']] = $v;
        }
        self::$rules = $new_rules;
    }

    public static function get($id_or_name)
    {
        if (isset(self::$rules[$id_or_name])) {
            return self::$rules[$id_or_name];
        }
        return [];
    }

    public static function all_number()
    {
        $d = [];
        foreach (self::$rules as $k => $v) {
            if (is_numeric($k)) {
                $d[] = $v;
            }
        }
        return $d;
    }

    public static function all_alpha()
    {
        $d = [];
        foreach (self::$rules as $k => $v) {
            if (!is_numeric($k)) {
                $d[] = $v;
            }
        }
        return $d;
    }
}

Menu::init();
